home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 43 / Mac Magazin and MacEasy Magazine CD - Issue 43.iso / Software / Multimedia / Sound / PlayerPRO 4.6 Dev.Kit / MADH Library 4.6 / MADLibrary Source / Effects.c < prev    next >
Encoding:
Text File  |  1998-01-23  |  9.7 KB  |  485 lines  |  [TEXT/CWIE]

  1. /********************                        ***********************/
  2. //
  3. //    Player PRO 4.6 - DRIVER SOURCE CODE -
  4. //
  5. //    Library Version 4.6
  6. //
  7. //    To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
  8. //
  9. //    Antoine ROSSET
  10. //    16 Tranchees
  11. //    1206 GENEVA
  12. //    SWITZERLAND
  13. //
  14. //    COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
  15. //
  16. //    Thank you for your interest in PlayerPRO !
  17. //
  18. //    FAX:            (+41 22) 346 11 97
  19. //    PHONE:             (+41 79) 203 74 62
  20. //    Internet:         rosset@dial.eunet.ch or RossetAntoine@bluewin.ch
  21. //
  22. /********************                        ***********************/
  23.  
  24. #include "RDriver.h"
  25. #include "RDriverInt.h"
  26.  
  27. #define LOW(para) ((para) & 15)
  28. #define HI(para) ((para) >> 4)
  29.  
  30. void parse_slidevol(Channel *ch, Byte Arg)
  31. {
  32.     if ( LOW( Arg) ) ch->volumerate = -LOW( Arg);
  33.     else ch->volumerate = HI( Arg);
  34. }
  35.  
  36. void DoEffect( Channel *ch, short call, MADDriverRec *intDriver)
  37. {
  38. long offset;
  39.     
  40.     switch( ch->cmd)
  41.     {
  42.         default:
  43.             ch->cmd = 0;
  44.             ch->arg = 0;
  45.             return;
  46.         break;
  47.     
  48.         case arpeggioE:                        // OK
  49.             if( ch->arg != 0 && ch->arp[ 0] != 0)
  50.             {
  51.                 ch->arpindex++;
  52.                 if( ch->arpindex >= MAX_ARP) ch->arpindex = 0;
  53.  
  54.                 ch->period = ch->arp[ ch->arpindex];
  55.             }
  56.         break;
  57.     
  58.         case skipE:                            // OK
  59.             if( call == intDriver->speed - 1)
  60.             {
  61.                 intDriver->endPattern = true;
  62.                 
  63.                 if( intDriver->JumpToNextPattern)
  64.                 {
  65.                     if( intDriver->PartitionReader != 0)
  66.                     {
  67.                         intDriver->PL++;
  68.                         intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  69.                     }
  70.                     
  71.                     intDriver->PartitionReader = HI( ch->arg) * 10 + LOW( ch->arg);
  72.                     
  73.                     if( intDriver->PL >= intDriver->curMusic->header->numPointers)
  74.                     {
  75.                         intDriver->PL = 0;
  76.                         intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  77.                         
  78.                         MADCleanDriver( intDriver);
  79.                         if( !intDriver->DriverSettings.repeatMusic) intDriver->Reading = false;
  80.                         
  81.                         intDriver->musicEnd = true;
  82.                     }
  83.                 }
  84.                 else
  85.                 {
  86.                     intDriver->PartitionReader = 0;
  87.                 }
  88.                 ch->cmd = 0;
  89.                 ch->arg = 0;
  90.             }
  91.         break;
  92.         
  93.         case fastskipE:                        // OK
  94.             if( call == intDriver->speed - 1)
  95.             {
  96.                 intDriver->endPattern = true;
  97.                 
  98.                 if( intDriver->JumpToNextPattern)
  99.                 {
  100.                     if( intDriver->PL > ch->arg)        // Evite les boucles
  101.                     {
  102.                         intDriver->musicEnd = true;
  103.                         
  104.                         if( !intDriver->DriverSettings.repeatMusic) intDriver->Reading = false;
  105.                     }
  106.                     
  107.                     intDriver->PL = ch->arg;
  108.                     intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  109.                 
  110.                     if( intDriver->PL >= intDriver->curMusic->header->numPointers)
  111.                     {
  112.                         intDriver->PL = 0;
  113.                         intDriver->Pat = intDriver->curMusic->header->oPointers[ intDriver->PL];
  114.                         
  115.                         MADCleanDriver( intDriver);
  116.                         if( !intDriver->DriverSettings.repeatMusic) intDriver->Reading = false;
  117.                         
  118.                         intDriver->musicEnd = true;
  119.                     }
  120.                 }
  121.                 intDriver->PartitionReader = 0;
  122.                 ch->cmd = 0;
  123.                 ch->arg = 0;
  124.             }
  125.         break;
  126.         
  127.         case downslideE:                        // OK
  128.             if( ch->period > intDriver->MIN_PITCH)
  129.                 ch->period -= ch->slide*4;
  130.         break;
  131.         
  132.         case upslideE:                            // OK
  133.             if( ch->period < intDriver->MAX_PITCH)
  134.                 ch->period += ch->slide*4;
  135.         break;
  136.         
  137.         case vibratoE:
  138.             
  139.             ch->viboffset += ch->vibrate;
  140.             ch->viboffset &= 63;
  141.             
  142.             offset = ((long) intDriver->vibrato_table[ ch->viboffset] * (long) ch->vibdepth) / 512L;
  143.             
  144.             ch->period = ch->periodOld + offset*4;
  145.         break;
  146.         
  147.         case slidevolE:                        // OK
  148.             ch->vol += ch->volumerate;
  149.             
  150.             if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  151.             else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  152.         break;
  153.         
  154.         case portamentoE:
  155.         //    if( ch->period == 0) DebugStr("\pGoal");
  156.             if( ch->period != ch->pitchgoal)
  157.             {
  158.                 if (ch->period < ch->pitchgoal)
  159.                 {
  160.                     ch->period += ch->pitchrate*4;
  161.                     if( ch->period > ch->pitchgoal)
  162.                     {
  163.                         ch->cmd = 0;
  164.                         ch->arg = 0;
  165.                         ch->period = ch->pitchgoal;
  166.                     }
  167.                 }
  168.                 else if (ch->period > ch->pitchgoal)
  169.                 {
  170.                     ch->period -= ch->pitchrate*4;
  171.                     if( ch->period < ch->pitchgoal)
  172.                     {
  173.                         ch->cmd = 0;
  174.                         ch->arg = 0;
  175.                         ch->period = ch->pitchgoal;
  176.                     }
  177.                 }
  178.             }
  179.         break;
  180.         
  181.         case portaslideE:
  182.             ch->cmd = portamentoE;
  183.             DoEffect( ch, call, intDriver);
  184.             
  185.             ch->cmd = slidevolE;
  186.             DoEffect( ch, call, intDriver);
  187.             
  188.             ch->cmd = portaslideE;
  189.         break;
  190.         
  191.         case vibratoslideE:
  192.             ch->cmd = vibratoE;
  193.             DoEffect( ch, call, intDriver);
  194.             
  195.             ch->cmd = slidevolE;
  196.             DoEffect( ch, call, intDriver);
  197.             
  198.             ch->cmd = vibratoslideE;
  199.         break;
  200.  
  201.         case extendedE:
  202.             switch( HI( ch->arg))
  203.               {
  204.                 case 12:
  205.                     if( call >= LOW( ch->arg)) ch->vol = 0;
  206.                 break;
  207.             }
  208.         break;
  209.     }
  210.     
  211.     if( call == intDriver->speed - 1)
  212.     {
  213.         ch->arg = 0;
  214.         ch->cmd = 0;
  215.     }
  216. }
  217.  
  218. void SetUpEffect( Channel *ch, MADDriverRec *intDriver)
  219. {
  220. short     temp, note;
  221. long    aL;
  222.  
  223. if( ch->arg == 0)
  224. {
  225.     switch( ch->cmd)
  226.     {
  227.         case arpeggioE:
  228.         case nothingE:
  229.         case fastskipE:
  230.         case volumeE:
  231.         case skipE:
  232.         case extendedE:
  233.         case speedE:
  234.         break;
  235.  
  236.         default:
  237.             ch->arg = ch->oldArg[ ch->cmd];
  238.         break;
  239.     }
  240. }
  241. else ch->oldArg[ ch->cmd] = ch->arg;
  242.  
  243. switch( ch->cmd)
  244. {        
  245.     case upslideE:                            // OK
  246.         if( ch->arg) ch->slide = ch->arg;
  247.     break;
  248.     
  249.     case downslideE:                        // OK
  250.         if( ch->arg) ch->slide = ch->arg;
  251.     break;
  252.  
  253.     case vibratoE:                            // OK
  254.         if( HI( ch->arg)) ch->vibrate = HI( ch->arg);
  255.         if( LOW( ch->arg)) ch->vibdepth = LOW( ch->arg);
  256.  
  257.         ch->periodOld = ch->period;
  258.     break;
  259.  
  260.     case arpeggioE:                        // OK
  261.         if( ch->arg == 0) ch->arp[ 0] = 0;
  262.         else
  263.         {
  264.             if( ch->note != 0xFF)
  265.             {
  266.                 note = ch->note + HI( ch->arg);
  267.                 if (note < NUMBER_NOTES) ch->arp[ 1] = GetOldPeriod( note, NOFINETUNE, intDriver);
  268.             
  269.                 note = ch->note + LOW( ch->arg);
  270.                 if (note < NUMBER_NOTES) ch->arp[ 2] = GetOldPeriod( note, NOFINETUNE, intDriver);
  271.            
  272.                 ch->arpindex = 0;
  273.                 ch->arp[ 0] = ch->period;
  274.             }
  275.         }
  276.     break;
  277.  
  278.     case slidevolE:                        // OK
  279.         parse_slidevol( ch, ch->arg);
  280.     break;
  281.     
  282.     case extendedE:
  283.         switch( HI( ch->arg))
  284.         {
  285.             case 0:        // Turn On/Off filter
  286.             break;
  287.             
  288.             case 1:        // Fineslide up
  289.                 temp = LOW( ch->arg);
  290.                 ch->period -= temp*4;
  291.             break;
  292.             
  293.             case 2:        // Fineslide down
  294.                 temp = LOW( ch->arg);
  295.                 ch->period += temp*4;
  296.             break;
  297.             
  298.             case 3:        // Set glissando on/off
  299.             break;
  300.             
  301.             case 4:        // Set vibrato waveform
  302.             break;
  303.             
  304.             case 5:        // Set finetune value
  305.             //    ch->fineTune    = finetune[ LOW( ch->arg)];
  306.             //    ch->period    = GetOldPeriod( ch->Amiga, ch->fineTune);
  307.             break;
  308.             
  309.             case 6:        // Loop pattern
  310.             break;
  311.             
  312.             case 7:        // Set tremolo waveform
  313.             break;
  314.             
  315.             case 8:        // Unused
  316.             break;
  317.             
  318.             case 9:
  319.             break;
  320.  
  321.             case 10:    // Fine volume slide up
  322.                 ch->vol += LOW( ch->arg);
  323.                 
  324.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  325.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  326.             break;
  327.             
  328.             case 11:    // Fine volume slide down
  329.                 ch->vol -= LOW( ch->arg);
  330.                 
  331.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  332.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  333.             break;
  334.             
  335.             case 12:    // Cut sample
  336.             break;
  337.             
  338.             case 13:    // Delay sample
  339.             break;
  340.             
  341.             case 14:    // Delay pattern
  342.             break;
  343.             
  344.             case 15:    // Invert loop
  345.             break;
  346.         }
  347.  
  348.     break;
  349.     
  350.     case portamentoE:                // OK
  351.         ch->pitchrate = ch->arg;
  352.  
  353.         if( ch->note != 0xFF)
  354.         {
  355.             ch->pitchgoal = GetOldPeriod( ch->note, ch->fineTune, intDriver);
  356.         }
  357.         else if( ch->pitchgoal == 0) ch->pitchgoal = ch->period;
  358.     break;
  359.     
  360.     case portaslideE:                // OK
  361.         if( ch->note != 0xFF)
  362.         {
  363.             ch->pitchgoal = GetOldPeriod( ch->note, ch->fineTune, intDriver);
  364.         }
  365.         else if( ch->pitchgoal == 0) ch->pitchgoal = ch->period;
  366.  
  367.         parse_slidevol(ch, ch->arg);
  368.     break;
  369.     
  370.     case vibratoslideE:
  371.         ch->periodOld = ch->period;
  372.  
  373.            parse_slidevol(ch, ch->arg);
  374.     break;
  375.     
  376.     case speedE:
  377.         if( ch->arg < 32)        /** Setting de la speed + reset de la finespeed **/
  378.         {
  379.             if( ch->arg != 0) intDriver->speed = ch->arg;
  380.         }
  381.         else        /** Setting de finespeed **/
  382.         {
  383.             intDriver->finespeed = ch->arg;
  384.         }
  385.     break;
  386.             
  387.     case skipE:
  388.     break;
  389.     
  390.     case fastskipE:
  391.     break;
  392.     
  393.     case offsetE:
  394.         ch->curPtr = ch->begPtr;
  395.  
  396.         aL = ch->arg;
  397.         aL *= 256L;
  398.  
  399.         ch->curPtr += aL;
  400.     break;
  401.     
  402.     case volumeE:
  403.         ch->vol = ch->arg;
  404.         
  405.         if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  406.         else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  407.     break;
  408.     }
  409. }
  410.  
  411. void DoVolCmd( Channel *ch, short call, MADDriverRec *intDriver)
  412. {
  413. short    vol = ch->volcmd;
  414. short    volLO = vol & 0xf;
  415.  
  416.     switch( vol >> 4)
  417.     {
  418.         case 0x6:                    // volslide down
  419.             ch->vol -= volLO;
  420.         
  421.             if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  422.             else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  423.         break;
  424.  
  425.         case 0x7:                    // volslide up
  426.             ch->vol += volLO;
  427.         
  428.             if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  429.             else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  430.         break;
  431.  
  432.         // volume-row fine volume slide is compatible with protracker
  433.         //   EBx and EAx effects i.e. a zero nibble means DO NOT SLIDE, as
  434.         //  opposed to 'take the last sliding value'.
  435.         //
  436.  
  437.         case 0x8:                        // finevol down
  438.             if( call == 1)
  439.             {
  440.                 ch->vol -= volLO;
  441.         
  442.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  443.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  444.             }
  445.         break;
  446.  
  447.         case 0x9:                       // finevol up
  448.             if( call == 1)
  449.             {
  450.                 ch->vol += volLO;
  451.         
  452.                 if( ch->vol < MIN_VOLUME) ch->vol = MIN_VOLUME;
  453.                 else if( ch->vol > MAX_VOLUME) ch->vol = MAX_VOLUME;
  454.             }
  455.         break;
  456.  
  457.         case 0xa:                       // set vibrato speed
  458.         break;
  459.  
  460.         case 0xb:                       // vibrato
  461.         break;
  462.  
  463.         case 0xc:                       // set panning
  464.         break;
  465.  
  466.         case 0xd:                       // panning slide left
  467.             // only slide when data nibble not zero:
  468.  
  469.             if(vol&0xf)
  470.             {
  471.             }
  472.             break;
  473.  
  474.         case 0xe:                       // panning slide right
  475.             // only slide when data nibble not zero:
  476.  
  477.             if(vol&0xf)
  478.             {
  479.             }
  480.         break;
  481.  
  482.         case 0xf:                       // tone porta
  483.         break;
  484.     }
  485. }